package com.gzdh.tang.modu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gzdh.tang.modu.entity.MacMainpSbruanKlDinner;
import com.gzdh.tang.modu.entity.MacMainpSbruanOrders;
import com.gzdh.tang.modu.entity.Reserve;
import com.gzdh.tang.modu.entity.ReserveXfjTemp;
import com.gzdh.tang.modu.mapper.MacMainpSbruanKlDinnerMapper;
import com.gzdh.tang.modu.mapper.MacMainpSbruanOrdersMapper;
import com.gzdh.tang.modu.service.MacMainpSbruanKlDinnerService;
import com.gzdh.tang.modu.service.MacMainpSbruanOrdersService;
import com.gzdh.tang.modu.service.ReserveService;
import com.gzdh.tang.modu.service.ReserveXfjTempService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service("macMainpSbruanOrdersServiceImpl")
public class MacMainpSbruanOrdersServiceImpl extends ServiceImpl<MacMainpSbruanOrdersMapper,
        MacMainpSbruanOrders> implements MacMainpSbruanOrdersService {


    @Autowired
    ReserveXfjTempService reserveXfjTempService;

    @Autowired
    ReserveService reserveService;

    @Override
    @Transactional
    public void paySuccessByDeviceOrders(String deviceOrders) {
        List<ReserveXfjTemp> reserveXfjTempList = reserveXfjTempService.list(new QueryWrapper<ReserveXfjTemp>()
                .lambda().eq(ReserveXfjTemp::getLsh2, deviceOrders));
        List<Reserve> reserveList = new ArrayList<>();
        for (ReserveXfjTemp goo : reserveXfjTempList) {
            Reserve reserve = new Reserve();
            BeanUtils.copyProperties(goo, reserve);
            reserveList.add(reserve);
        }
        reserveService.saveBatch(reserveList);
        this.lambdaUpdate().set(MacMainpSbruanOrders::getState, 1)
                .eq(MacMainpSbruanOrders::getDeviceOrder, deviceOrders).update();
    }
}
